 package client.inventory;

 import com.alibaba.druid.pool.DruidPooledConnection;
 import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import database.DatabaseConnection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;










 public class MaplePotionPot
 {
   private final int chrId;
   private final int itemId;
/*  23 */   private final int maxlimit = 10000000;
   private final long startTime;
   private final long endTime;
   private int hp;
   private int mp;
   private int maxValue;

   @JsonCreator
   public MaplePotionPot(@JsonProperty("chrId") int chrId, @JsonProperty("itemId") int itemId, @JsonProperty("hp") int hp, @JsonProperty("mp") int mp, @JsonProperty("maxValue") int maxValue, @JsonProperty("startTime") long start, @JsonProperty("endTime") long end) {
/*  32 */     this.chrId = chrId;
/*  33 */     this.itemId = itemId;
/*  34 */     this.hp = hp;
/*  35 */     this.mp = mp;
/*  36 */     this.maxValue = maxValue;
/*  37 */     this.startTime = start;
/*  38 */     this.endTime = end;
   }




   public static MaplePotionPot createPotionPot(int chrId, int itemId, long endTime) {
/*  45 */     if (itemId != 5820000) {
/*  46 */       return null;
     }
/*  48 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
/*  49 */       PreparedStatement ps = con.prepareStatement("INSERT INTO `character_potionpots` (`characterid`, `itemId`, `hp`, `mp`, `maxValue`, `startDate`, `endDate`) VALUES (?, ?, ?, ?, ?, ?, ?)");
/*  50 */       ps.setInt(1, chrId);
/*  51 */       ps.setInt(2, itemId);
/*  52 */       ps.setInt(3, 0);
/*  53 */       ps.setInt(4, 0);
/*  54 */       ps.setInt(5, 1000000);
/*  55 */       ps.setLong(6, System.currentTimeMillis());
/*  56 */       ps.setLong(7, endTime);
/*  57 */       ps.executeUpdate();
/*  58 */       ps.close();
/*  59 */     } catch (SQLException ex) {
/*  60 */       System.err.println("创建药剂罐信息出错 " + ex);
/*  61 */       return null;
     }
/*  63 */     return new MaplePotionPot(chrId, itemId, 0, 0, 1000000, System.currentTimeMillis(), endTime);
   }




   public void saveToDb(DruidPooledConnection con) {
     try {
/*  71 */       PreparedStatement ps = con.prepareStatement("UPDATE `character_potionpots` SET `hp` = ?, `mp` = ?, `maxValue` = ? WHERE `characterid` = ?");
/*  72 */       ps.setInt(1, this.hp);
/*  73 */       ps.setInt(2, this.mp);
/*  74 */       ps.setInt(3, this.maxValue);
/*  75 */       ps.setInt(4, this.chrId);
/*  76 */       ps.executeUpdate();
/*  77 */       ps.close();
/*  78 */     } catch (SQLException ex) {
/*  79 */       System.err.println("保存药剂罐信息出错" + ex);
     }
   }




   public int getChrId() {
/*  87 */     return this.chrId;
   }




   public int getItmeId() {
/*  94 */     return this.itemId;
   }




   public int getHp() {
/* 101 */     if (this.hp < 0) {
/* 102 */       this.hp = 0;
/* 103 */     } else if (this.hp > this.maxValue) {
/* 104 */       this.hp = this.maxValue;
     }
/* 106 */     return this.hp;
   }

   public void setHp(int value) {
/* 110 */     this.hp = value;
   }

   public void addHp(int value) {
/* 114 */     if (value <= 0) {
       return;
     }
/* 117 */     this.hp += value;
/* 118 */     if (this.hp > this.maxValue) {
/* 119 */       this.hp = this.maxValue;
     }
   }




   public int getMp() {
/* 127 */     if (this.mp < 0) {
/* 128 */       this.mp = 0;
/* 129 */     } else if (this.mp > this.maxValue) {
/* 130 */       this.mp = this.maxValue;
     }
/* 132 */     return this.mp;
   }

   public void setMp(int value) {
/* 136 */     this.mp = value;
   }

   public void addMp(int value) {
/* 140 */     if (value <= 0) {
       return;
     }
/* 143 */     this.mp += value;
/* 144 */     if (this.mp > this.maxValue) {
/* 145 */       this.mp = this.maxValue;
     }
   }






   public int getMaxValue() {
/* 155 */     if (this.maxValue > 10000000) {
/* 156 */       this.maxValue = 10000000;
     }
/* 158 */     return this.maxValue;
   }

   public void setMaxValue(int value) {
/* 162 */     this.maxValue = value;
   }

   public boolean addMaxValue() {
/* 166 */     if (this.maxValue + 1000000 > 10000000) {
/* 167 */       return false;
     }
/* 169 */     this.maxValue += 1000000;
/* 170 */     return true;
   }




   public long getStartDate() {
/* 177 */     return this.startTime;
   }




   public long getEndDate() {
/* 184 */     return this.endTime;
   }




   public boolean isFullHp() {
/* 191 */     return (getHp() >= getMaxValue());
   }

   public boolean isFullMp() {
/* 195 */     return (getMp() >= getMaxValue());
   }

   public boolean isFull(int addHp, int addMp) {
/* 199 */     if (addHp > 0 && addMp > 0)
/* 200 */       return (isFullHp() && isFullMp()); 
/* 201 */     if (addHp > 0 && addMp == 0)
/* 202 */       return isFullHp(); 
/* 203 */     if (addHp == 0 && addMp >= 0) {
/* 204 */       return isFullMp();
     }
/* 206 */     return true;
   }
 }


/* Location:              C:\PGX\Server.jar!\client\inventory\MaplePotionPot.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */